<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>ef code first简单示例 | haijd</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="Asp.Net MVCEntityFramework" />
  
  
  
  
  <meta name="description" content="EF code first简单示例">
<meta name="keywords" content="Asp.Net MVC,EntityFramework">
<meta property="og:type" content="article">
<meta property="og:title" content="EF code first简单示例">
<meta property="og:url" content="http://www.hais2.com/2016/04/13/EF-code-first-simple-example/index.html">
<meta property="og:site_name" content="haijd">
<meta property="og:description" content="EF code first简单示例">
<meta property="og:locale" content="default">
<meta property="og:image" content="http://ww1.sinaimg.cn/mw690/c55a7aeegw1f2v56p11fvj20m80h8tc1.jpg">
<meta property="og:image" content="http://ww2.sinaimg.cn/mw690/c55a7aeegw1f2v5ax49q3j207x0ec74j.jpg">
<meta property="og:image" content="http://ww4.sinaimg.cn/mw690/c55a7aeegw1f2v5pqpkftj218g0oeq68.jpg">
<meta property="og:image" content="http://ww4.sinaimg.cn/mw690/c55a7aeegw1f2v6lnz9r9j20at0823ym.jpg">
<meta property="og:image" content="http://ww2.sinaimg.cn/mw690/c55a7aeegw1f2v8j7u70cj20dd07ggm1.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/mw690/c55a7aeegw1f2v8ojeym7j20g70610sv.jpg">
<meta property="og:updated_time" content="2017-08-02T15:22:33.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="EF code first简单示例">
<meta name="twitter:description" content="EF code first简单示例">
<meta name="twitter:image" content="http://ww1.sinaimg.cn/mw690/c55a7aeegw1f2v56p11fvj20m80h8tc1.jpg">
  
    <link rel="alternate" href="/atom.xml" title="haijd" type="application/atom+xml">
  
  <link rel="icon" href="/css/images/favicon.ico">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/9749f0/00000000000000000001008f/27/l?subset_id=2&fvd=n5) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/90cf9f/000000000000000000010091/27/l?subset_id=2&fvd=n7) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/8a5494/000000000000000000013365/27/l?subset_id=2&fvd=n4) format("woff2");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/d337d8/000000000000000000010095/27/l?subset_id=2&fvd=i4) format("woff2");font-weight:400;font-style:italic;}</style>
    
  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Yanone+Kaffeesatz%3A200%2C300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">
  <link rel="stylesheet" href="/css/style.css">

  <script src="/js/jquery-3.1.1.min.js"></script>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css" >
  <link rel="stylesheet" href="/css/hiero.css" >
  <link rel="stylesheet" href="/css/glyphs.css" >
  
    <link rel="stylesheet" href="/css/vdonate.css" >
  

</head>

<script>
var themeMenus = {};

  themeMenus["/"] = "Home"; 

  themeMenus["/archives"] = "Archives"; 

  themeMenus["/categories"] = "Categories"; 

  themeMenus["/tags"] = "Tags"; 

  themeMenus["/about"] = "About"; 

</script>


  <body data-spy="scroll" data-target="#toc" data-offset="50">


  <header id="allheader" class="site-header" role="banner">
  <div class="clearfix container">
      <div class="site-branding">

          <h1 class="site-title">
            
              <a href="/" title="haijd" rel="home"> haijd </a>
            
          </h1>

          
            <div class="site-description">Stay Hungry,Stay Foolish</div>
          
            
          <nav id="main-navigation" class="main-navigation" role="navigation">
            <a class="nav-open">Menu</a>
            <a class="nav-close">Close</a>
            <div class="clearfix sf-menu">

              <ul id="main-nav" class="nmenu sf-js-enabled">
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/">Home</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/archives">Archives</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/categories">Categories</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/tags">Tags</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/about">About</a> </li>
                    
              </ul>
            </div>
          </nav>


      </div>
  </div>
</header>




  <div id="container">
    <div id="wrap">
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-EF-code-first-simple-example" style="width: 66%; float:left;" class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" class="article-title" itemprop="name">
      EF code first简单示例
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	Posted on <a href="/2016/04/13/EF-code-first-simple-example/" class="article-date">
	  <time datetime="2016-04-13T12:35:53.000Z" itemprop="datePublished">April 13, 2016</time>
	</a>

      
	<span id="busuanzi_container_page_pv">
	  本文总阅读量<span id="busuanzi_value_page_pv"></span>次
	</span>

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>　　一个简单的MVC5+EF6小demo，演示mvc和ef的简单编写流程。</p>
<h2 id="创建项目"><a href="#创建项目" class="headerlink" title="创建项目"></a>创建项目</h2><p>　　1、选择.Net Farmework版本为4.5以上的，这里我选择4.5.2<br>　　2、选择模板，选择<strong>Empty</strong>，勾选MVC引用：<img src="http://ww1.sinaimg.cn/mw690/c55a7aeegw1f2v56p11fvj20m80h8tc1.jpg" alt=""><a id="more"></a><br>　　可以看到VS自动帮我们添加了asp.net MVC默认约定的文件夹，按照asp.net MVC的约定大于配置的原则，不要随意改变文件夹的名字，也不要将文件随意添加，不然可能导致程序出错。<img src="http://ww2.sinaimg.cn/mw690/c55a7aeegw1f2v5ax49q3j207x0ec74j.jpg" alt=""><br>　　关于基本项目文件的说明：<br>　　<code>App_Start</code>：一些全局的配置类，配合<code>Global</code>使用。<br>　　<code>Controllers</code>：存放MVC控制器的文件夹。<br>　　<code>Models</code>：存放数据模型(class)文件夹。<br>　　<code>Views</code>：存放视图的文件夹。</p>
<h2 id="添加EF组件"><a href="#添加EF组件" class="headerlink" title="添加EF组件"></a>添加EF组件</h2><p>　　EntityFarmework是作为组件的形式存在的，要使用EntityFarmework需要添加它的引用。<br>　　1、使用Nuget添加EF：右击引用==&gt;管理NuGet程序包，会弹出NuGet管理界面。<br>　　2、点击“浏览”按钮，可以看到“EntityFramework”作为常用组件会排列在第一位，选择后，点击右边的“安装”按钮即可进行安装。<img src="http://ww4.sinaimg.cn/mw690/c55a7aeegw1f2v5pqpkftj218g0oeq68.jpg" alt=""></p>
<h2 id="添加User数据模型，并且使用code-first自动生成数据库"><a href="#添加User数据模型，并且使用code-first自动生成数据库" class="headerlink" title="添加User数据模型，并且使用code first自动生成数据库"></a>添加User数据模型，并且使用code first自动生成数据库</h2><p>　　1、在“Models”文件夹中添加一个名为<code>User</code>的类，并添加以下内容：<br><figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">int</span> Id &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br><span class="line"></span><br><span class="line">[<span class="meta">Required(ErrorMessage = <span class="meta-string">"用户名必填"</span>)</span>]</span><br><span class="line">[<span class="meta">Display(Name = <span class="meta-string">"用户名"</span>)</span>]</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">string</span> Name &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br><span class="line"></span><br><span class="line">[<span class="meta">Required(ErrorMessage=<span class="meta-string">"密码必填"</span>)</span>]</span><br><span class="line">[<span class="meta">Display(Name=<span class="meta-string">"密码"</span>)</span>]</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">string</span> Pwd &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br></pre></td></tr></table></figure></p>
<p>　　注：需要添加一个命名空间<code>System.ComponentModel.DataAnnotations</code>，代码中的特性标签是作为数据注解使用的，关于数据注解，在下一篇中总结。</p>
<p>　　2、添加数据库上下文类：<br>　　在“Models”文件夹中添加一个名为<code>DbEntities</code>的类作为数据库上下文类，该类需要继承<code>DbContext</code>类。然后添加如下代码：<br><figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">DbEntities</span>:<span class="title">DbContext</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">//base中的字符串为web.config中设置的数据库连接字符串名</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">DbEntities</span>(<span class="params"></span>):<span class="title">base</span>(<span class="params"><span class="string">"name=SQLConnString"</span></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="comment">//表示创建数据库的方式</span></span><br><span class="line">        Database.SetInitializer&lt;DbEntities&gt;(<span class="keyword">new</span> CreateDatabaseIfNotExists&lt;DbEntities&gt;());</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//存储User数据的属性</span></span><br><span class="line">    <span class="keyword">public</span> DbSet&lt;User&gt; User &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>　　3、配置数据库连接字符串<br>　　打开“web.config”文件，添加数据库连接字符串，比如：<br>　　因为目前为止还没有创建数据库，所以这里指定数据库名称时，可以随意起一个不重复的名字即可，创建时，就会自动按照该名称创建数据库。<br>　　同时注意，连接字符串的<code>name</code>属性的值和数据库上下文中<code>base</code>的值要一致。<br><figure class="highlight nix"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;connectionStrings&gt;</span><br><span class="line">  &lt;add <span class="attr">name="SQLConnString"</span> <span class="attr">providerName="System.Data.SqlClient"</span> <span class="attr">connectionString="Data</span> <span class="attr">Source=.;Initial</span> <span class="attr">Catalog=MVC5_Test;Persist</span> Security <span class="attr">Info=True;User</span> <span class="attr">ID=sa;Password=sa"</span> /&gt;</span><br><span class="line">&lt;/connectionStrings&gt;</span><br></pre></td></tr></table></figure></p>
<p>　　4、使用EF数据迁移创建数据库<br>　　依次点击：工具==&gt;NuGet包管理器==&gt;程序包管理控制台，打开power shell窗口。<br>　　输入：<br>　　　　<code>Enable-Migrations</code>：表示开启该项目的数据迁移功能，只需运行依次，以后迁移数据时，不需要再运行该命令。<br>　　　　<code>Add-Migration migrationName</code>：添加迁移命令，需要给本次迁移起一个名字(如migrationName)，这时还没有开始迁移，只是打上了迁移的标记。<br>　　　　<code>Update-Database</code>：将迁移更新到数据库中。<br>　　三条命令全部成功执行后，不出意外的话，数据库中应该已经创建了相应的数据库、表、字段：<img src="http://ww4.sinaimg.cn/mw690/c55a7aeegw1f2v6lnz9r9j20at0823ym.jpg" alt=""><br>　　同时，项目中也为我们自动添加了一个名为“Migrations”的文件夹，里面有两个文件，分别是数据迁移的配置类(Configuration)、数据迁移的内容(xxxxx_migrationName)。</p>
<h2 id="编写简单的登录页面"><a href="#编写简单的登录页面" class="headerlink" title="编写简单的登录页面"></a>编写简单的登录页面</h2><p>　　我们可以直接在数据库中添加一条用户登录的数据，Name=admin,Pwd=123456<br>　　1、添加控制器：<br>　　　　在“Controllers”文件夹右击，添加==&gt;控制器，在弹出的窗口中选择“MVC5控制器 空”，然后起名为<code>HomeController</code>。<br>　　2、添加首页视图：<br>　　　　可以看到，自动为我们生成了一个<code>Index</code>方法，光标停在<code>Index</code>上面，然后鼠标右击，在弹出的菜单中选择“添加视图”，然后在弹出窗口中不修改视图的名字(按照约定，视图的名字必须和控制器方法名一致)，去除“使用布局页”前面的对勾(关于如何使用布局页将在另一篇博客中总结)，点击添加。<br>　　3、在Index视图中添加表单：<br>　　　　VS帮我们生成了一个基础的Razor模板，我们在<code>&lt;body&gt;&lt;/body&gt;</code>中添加表单内容：<br>　　关于@html辅助方法，在前面的<a href="http://www.hais2.com/2015/08/02/HTML%E8%BE%85%E5%8A%A9%E6%96%B9%E6%B3%95/">博客</a>中简单总结了一下。<br>　　在页面开头我们还需要引入在Razor中使用的数据模型的完全限定名，使用<code>@model</code>引入，比如<code>@model Mvc5_EF6_Demo.Models.User</code><br><figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">@using</span> (Html.BeginForm(<span class="string">"Index"</span>, <span class="string">"Home"</span>))</span><br><span class="line">&#123;</span><br><span class="line">       <span class="variable">@Html</span>.ValidationSummary(true)</span><br><span class="line">       &lt;h1&gt;请输入用户名密码登陆&lt;/h1&gt;</span><br><span class="line">       <span class="variable">@Html</span>.LabelFor(model =&gt; model.Name)</span><br><span class="line">       <span class="variable">@Html</span>.TextBoxFor(model =&gt; model.Name)</span><br><span class="line">       <span class="variable">@Html</span>.ValidationMessageFor(model =&gt; model.Name)</span><br><span class="line">       &lt;br /&gt;</span><br><span class="line">       <span class="variable">@Html</span>.LabelFor(model =&gt; model.Pwd)</span><br><span class="line">       <span class="variable">@Html</span>.TextBoxFor(model =&gt; model.Pwd)</span><br><span class="line">       <span class="variable">@Html</span>.ValidationMessageFor(model =&gt; model.Pwd)</span><br><span class="line">       &lt;br /&gt;</span><br><span class="line">       &lt;input type=<span class="string">"submit"</span> value=<span class="string">"登陆"</span> /&gt;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>　　4、添加登录事件处理方法：<br>　　在<code>HomeController</code>控制器中创建一个名为<code>Index</code>的方法，因为表单的发送地址执行了Index方法，但是现在又两个Index方法，这是程序不允许的，需要进行处理。<br>　　由于表单是post请求发送的，在接收表单的Index方法上面写上一个特性标签<code>[HttpPost]</code>，表示该方法只响应post请求，然后接收参数为<code>User</code>类型的一个参数，代码如下：<br><figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">[HttpPost]</span><br><span class="line">public ActionResult <span class="built_in">Index</span>(User user)<span class="comment">//将表单中的输入自动组成User类，传递到Login方法</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">//判断表单模型是否验证成功</span></span><br><span class="line">    <span class="keyword">if</span> (!ModelState.IsValid)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">View</span>(user);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//如果表单验证成功</span></span><br><span class="line">    <span class="comment">//创建数据上下文类对象</span></span><br><span class="line">    DbEntities <span class="keyword">db</span> = new DbEntities();</span><br><span class="line">    <span class="comment">//查找User表中的所有数据,转换成List类型</span></span><br><span class="line">    <span class="keyword">var</span> userInfo = <span class="keyword">db</span>.User.Select(s =&gt; s).ToList();</span><br><span class="line">    <span class="comment">//简单的判断一下输入和数据库是否相同</span></span><br><span class="line">    <span class="keyword">if</span> (userInfo[0].Name==user.Name&amp;&amp;userInfo[0].<span class="keyword">Pwd</span>==user.<span class="keyword">Pwd</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">//跳转到登录成功的Action</span></span><br><span class="line">        <span class="keyword">return</span> RedirectToAction(<span class="string">"LoginOk"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">View</span>(user);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>　　5、添加登录成功视图：<br>　　在<code>HomeController</code>控制器中增加一个<code>LoginOk</code>方法并且添加视图，用来展示登录成功页面</p>
<h2 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h2><p>　　启动项目，测试：<br>　　1、我们少填一个字段：<br>　　<img src="http://ww2.sinaimg.cn/mw690/c55a7aeegw1f2v8j7u70cj20dd07ggm1.jpg" alt=""><br>　　可以看到，不填写的话，就会显示相应的提示，因为我们在数据模型中添加了<code>[Required]</code>特性标签，就是必填的意思，然后在提交到Action中时，使用<code>ModelState.IsValid</code>进行判断。<br>　　2、验证成功：<br>　　<img src="http://ww1.sinaimg.cn/mw690/c55a7aeegw1f2v8ojeym7j20g70610sv.jpg" alt=""><br>　　3、验证失败：<br>　　暂时没有验证，所以会跳转到Index页面。</p>
<p><a href="http://pan.baidu.com/s/1boCP2RP" target="_blank" rel="noopener">代码下载</a></p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
	<span class="ico-folder"></span>
    <a class="article-category-link" href="/categories/Asp-Net-MVC/">Asp.Net MVC</a>

      
  <span class="ico-tags"></span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Asp-Net-MVC/">Asp.Net MVC</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/EntityFramework/">EntityFramework</a></li></ul>

      
        <div id="donation_div"></div>

<script src="/js/vdonate.js"></script>
<script>
var a = new Donate({
  title: '如果觉得我的文章对您有用，请随意打赏。您的支持将鼓励我继续创作!', // 可选参数，打赏标题
  btnText: 'Donate', // 可选参数，打赏按钮文字
  el: document.getElementById('donation_div'),
  wechatImage: '/css/images/wechatPay.png',
  alipayImage: '/css/images/alipay.jpg'
});
</script>
      

      
        
	<section id="comments" class="comment">
	  <div id="disqus_thread">
	  <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
	  </div>
	</section>

	<script type="text/javascript">
	var disqus_shortname = 'haijdblog';
	(function(){
	  var dsq = document.createElement('script');
	  dsq.type = 'text/javascript';
	  dsq.async = true;
	  dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
	  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	}());
	(function(){
	  var dsq = document.createElement('script');
	  dsq.type = 'text/javascript';
	  dsq.async = true;
	  dsq.src = '//' + disqus_shortname + '.disqus.com/count.js';
	  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	}());
	</script>


      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2016/04/20/Guid-ToString-overload-of-the-format/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Guid.ToString()的格式化重载
        
      </div>
    </a>
  
  
    <a href="/2016/03/28/Git-command-summary/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">git常用命令总结</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">Contents</strong>
    
      <ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#创建项目"><span class="nav-number">1.</span> <span class="nav-text">创建项目</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#添加EF组件"><span class="nav-number">2.</span> <span class="nav-text">添加EF组件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#添加User数据模型，并且使用code-first自动生成数据库"><span class="nav-number">3.</span> <span class="nav-text">添加User数据模型，并且使用code first自动生成数据库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#编写简单的登录页面"><span class="nav-number">4.</span> <span class="nav-text">编写简单的登录页面</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#测试"><span class="nav-number">5.</span> <span class="nav-text">测试</span></a></li></ol>
    
    </div>
  </aside>
</section>
        
      </div>
      <footer id="footer" class="site-footer">
  

  <div class="clearfix container">
      <div class="site-info">
	      &copy; 2018 haijd All Rights Reserved.
          
            <span id="busuanzi_container_site_uv">
              本站访客数<span id="busuanzi_value_site_uv"></span>人次  
              本站总访问量<span id="busuanzi_value_site_pv"></span>次
            </span>
          
      </div>
      <div class="site-credit">
        Theme by <a href="https://github.com/iTimeTraveler/hexo-theme-hiero" target="_blank">hiero</a>
      </div>
  </div>
</footer>


<!-- min height -->

<script>
    var contentdiv = document.getElementById("content");

    contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/scripts.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/main.js"></script>








	<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js" async=""></script>
</body>
</html>
